//
//  FormEditor.h
//  iBasic
//
//  Created by Andrew Barry on 22/04/08.
//  Copyright 2008 Barry Computer Services. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "FormControl.h"

@class JavascriptForm;
@class FormEditor;
@class FormView;
@class FormControl;

@interface FormEditorOverlay : NSView {
	NSMutableArray *selection;
	NSView *highlightView;
	NSDictionary *vAligns, *hAligns;
	bool hasSelectionRect;
	NSRect selectionRect;
}
- (void) addSelectedObject: (id) obj;
- (void) removeSelectedObject: (id) obj;
- (void) setSelectedObject: (id) obj;
- (BOOL) isSelected: (id) obj;
- (BOOL) hasSelection;
- (NSArray *) selection;
-(NSView *) highlightView;
-(void) setHightlightView: (NSView *) view;
-(void) setHorizontalAligns: (NSDictionary *) aligns;
-(void) setVerticalAligns: (NSDictionary *) aligns;
-(void) setSelectionRect: (NSRect) r;
-(void) clearSelectionRect;
@end


@interface FormEditor : NSView {
	FormEditorOverlay *overlay;
	NSMutableArray *controls;
	BOOL dragHandle;
	NSView *handleControl;
	int handleCorner;
	NSRect handleFrame;
	JavascriptForm *formDocument;

	NSString *projType;
	int formWidth, formHeight;
	bool canResize, canZoom, canClose;
	bool hasBackgroundColor;
	NSColor *backgroundColor;
	NSString *formTitle, *frameAutosave;
	bool formStartup;
	FormView *formview;
	int kind;
	
	NSPoint lastMouse, selEndMouse;
	NSRect currentSelection;
	FormControl *draggingControl;
	bool draggingSelection;
	NSArray *initialSelection;
	
	NSString *formLoadEvent, *formUnloadEvent, *formEnableControlsEvent;
}
-(NSString *) projType;
-(BOOL) isWebForm;

- (void) setOverlay: (FormEditorOverlay *) ovl;
- (void) setFormView: (FormView *) ovl;
- (void) loadForm: (NSDictionary *) toDict;
- (NSMutableDictionary *) saveForm;
-(void) setDocument: (JavascriptForm *) doc;
-(FormControl *)controlFromView:(NSView *) view;
-(FormControl *) controlByName: (NSString *) controlName;
-(void) showInfo;
-(void) commitSource: (NSString *) content forObject: (id) obj forEvent: (NSString *) eventName;
-(NSString *) sourceForObject: (id) obj forEvent: (NSString *) eventName;
-(NSString *) getDefaultNameForType: (NSString *) typeName;
-(NSArray *) controls;
-(void) selectControl: (FormControl *) ctl;
-(NSArray *) getFormEvents;
+(NSArray *) getFormEvents;
-(id) valueForProperty: (NSString *) name;
-(void) setValue: (id) val forProperty:(NSString*) name;
-(void) postLoad;
-(void) updateControlPanel;
-(void) updateSelectedObject;

@end
/*
@interface PropertiesPane : NSObject {
    IBOutlet NSWindow *window;
	IBOutlet id controller;
	id object;
	JavascriptForm *doc;
}
-(NSWindow *) window;
-(void) setObject: (id) obj;
-(void) setDocument: (JavascriptForm *) obj;
-(void) setValue: (id) val forProperty:(NSString*) name;
-(void) updateValue: (id) val forProperty: (NSString*) key;

-(id) object;
@end
*/